﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace 台签打印
{
    class XmlData
    {
        public static T LoadXml<T>(string xmlfile = "data.xml")
        {
            if (File.Exists(xmlfile))
            {
                using (var sr = new StreamReader(xmlfile, Encoding.UTF8))
                {
                    XmlSerializer xz = new XmlSerializer(typeof(T));
                    return (T)xz.Deserialize(sr);
                }
            }
            return default;
        }

        public static void SaveXml<T>(T t, string xmlfile = "data.xml")
        {
            using (var sw = new StreamWriter(xmlfile, false, Encoding.UTF8))
            {
                XmlSerializer xz = new XmlSerializer(typeof(T));
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add("Name", "https://gitee.com/zhux3/seat-print");
                xz.Serialize(sw, t, ns);
            }
        }

    }
}
